package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 查询关联分类的菜品数量
     * @param id
     * @return
     */
    int queryByCategoryId(Long id);

    /**
     * 菜品添加
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    @Insert("insert into dish (name, category_id, price, image, description, create_time, update_time, create_user, update_user,status) " +
            "values (#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status});")
    //获取自增主键
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id", before = false, resultType = Long.class)
    void insert(Dish dish);

    List<DishVO> queryByPage(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 批量删除
     * @param ids
     */
    void deleteById(Integer[] ids);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id};")
    Dish queryById(Integer id);

    /**
     * 根据id查询，进行双表查询并封装数据
     * @param id
     * @return
     */
    DishVO queryByDishVo(Integer id);

    /**
     * 菜品修改
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据分类id查询
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId};")
    List<Dish> queryByCategory(Integer categoryId);

    List<DishVO> queryByDishVoWithCategoryId(Long categoryId);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
